//
//  EighteenViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/12/29.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class EighteenViewController: UIViewController {

    var sandView:sandBoxView?
    var sand2View:sandBox2View?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white;
        // Do any additional setup after loading the view.
        self.onCreatUIForNivation();
        
        let bt = UIButton(type: .custom);
        bt.backgroundColor = .darkGray;
        bt.frame = CGRect(x: 100, y: 200, width: 100, height: 60);
        bt.setTitle("点击", for: .normal);
        bt.setTitleColor(.white, for: .normal);
        bt.addTarget(self, action: #selector(onClick), for: .touchUpInside);
        self.view.addSubview(bt);
        
        sandView = sandBoxView(frame: CGRect.zero);
        self.view.addSubview(sandView!);
        
        sand2View = sandBox2View(frame: CGRect.zero);
        self.view.addSubview(sand2View!);
    }
    
    fileprivate func onCreatUIForNivation() {
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", style: .done, target: self, action: #selector(onBackAction));
    }

    @objc func onClick() {
        let name = sandView?.nameText;
        print("值:\(name ?? "11")")
        
        sandView?.onTapSandBoxAction("你大爷");
        
        let name2 = sand2View?.nameText;
        print("OO:\(name2 ?? "11")")
        
        sand2View?.onTapSandBoxAction("你大爷2");
    }

    //TODO:Actions
    @objc fileprivate func onBackAction() {
        self.navigationController?.dismiss(animated: true, completion: nil);
    }
}
